import React from 'react'

class Header extends React.Component {
    constructor(props) {
        super(props);
        this.state = {  
            title: "这是一个头部组件",
            msg: "这是一个头部组件"
        };
    }
    getNews = () => {
        alert(this.props.news.state.msg);
        this.props.news.getData();
    }
    render() {
        return (
            <div>
            <h2>{this.props.title}</h2>
            <button onClick={this.props.run}>调用New父组件的run方法</button>
            <br/><br/>
            <button onClick={this.props.news.getData}>获取news组件的getData方法</button>
            <br/><br/>
            <button onClick={this.getNews}>获取整个news组件的实例</button>
            <br/><br/>
            <button onClick={this.props.news.getChildData.bind(this, "header组件传值")}>给父组件传值</button>
            </div>
        );
    }
}

export default Header;